package com.imisty.interceptor;

import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.*;

import java.sql.Statement;
import java.util.Properties;

/**
 * 定义mybatis的拦截器
 */
//进行插件签名，声明mybatis插件拦截哪个目标对象的哪个方法

    @Intercepts(
            //这里的参数类型为 @Signature 注解数组
            {@Signature(type = ResultSetHandler.class,method = "handleResultSets",args = Statement.class)
    })
public class MySecondInterceptor implements Interceptor {


    //拦截目标对象的目标方法的
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("second plugin intercept : 拦截的目标对象"+invocation.getTarget());
        //执行拦截的方法并返回
        Object obj = invocation.proceed();

        return obj;
    }

    //包装目标对象，为目标对象创建代理对象
    public Object plugin(Object o) {
        System.out.println("second plugin : 将要包装的目标对象"+o);
        return Plugin.wrap(o,this);
    }

    public void setProperties(Properties properties) {

        System.out.println("second plugin : 插件配置的初始化参数"+properties);
    }
}
